/*
 * Copyright 2013 Agustina Martinez-Garcia

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package uk.ljmu.metadata.staticschemas;

import java.io.InputStream;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;

public class StaticQudex {
    /** <p>The RDF model that holds the vocabulary terms</p> */
    private static Model m_model = ModelFactory.createDefaultModel();
    
    /** <p>The namespace of the vocabulary as a string</p> */
    public static final String NS = "http://example.org/qudex/";
    
    /** <p>The namespace of the vocabulary as a string</p>
     *  @see #NS */
    public static String getURI() {return NS;}
    
    /** <p>The namespace of the vocabulary as a resource</p> */
    public static final Resource NAMESPACE = m_model.createResource( NS );
    
    /** <p>The value of a particular Qudex Code</p> */
    public static final Property code = m_model.createProperty( "http://example.org/qudex/code" );
    
    /** <p>The label of a particular Qudex Code.</p> */
    public static final Property labelCode = m_model.createProperty( "http://example.org/qudex/labelCode" );
    
    /** <p>The value of a particular Qudex Category.</p> */
    public static final Property category = m_model.createProperty( "http://example.org/qudex/category" );
    
    /** <p>The label of a particular Qudex Category.</p> */
    public static final Property labelCategory = m_model.createProperty( "http://example.org/qudex/labelCategory" );
    
    /** <p>The value of a particular Qudex Memo.</p> */
    public static final Property memo = m_model.createProperty( "http://example.org/qudex/memo" );
    
    /** <p>The label of a particular Qudex Memo.</p> */
    public static final Property labelMemo = m_model.createProperty( "http://example.org/qudex/labelMemo" );
    
    /** <p>Expresses whether the resource is a original source or a document surrogate.</p> */
    public static final Property isOriginal = m_model.createProperty( "http://example.org/qudex/isOriginal" );
    
    /** <p>Identifier of the Fedora object to update.</p> */
    public static final Property updatePid = m_model.createProperty( "http://example.org/qudex/updatePid" );
    
    /** <p>Identifier of the Fedora object to delete.</p> */
    public static final Property deletePid = m_model.createProperty( "http://example.org/qudex/deletePid" );
    
    /** <p>Identifier of the Fedora object to delete.</p> */
    public static final Property isLinkedTo = m_model.createProperty( "http://example.org/qudex/isLinkedTo" );
    
    /** <p>Identifier of the Fedora object to delete.</p> */
    public static final Property isRelatedTo = m_model.createProperty( "http://example.org/qudex/isRelatedTo" );
    
    /** <p>Identifier of the Fedora object to delete.</p> */
    public static final Property isAnnotationOf = m_model.createProperty( "http://example.org/qudex/isAnnotationOf" );
    
    /** <p>Identifier of the Fedora object to delete.</p> */
    public static final Property isVersionOf = m_model.createProperty( "http://example.org/qudex/isVersionOf" );
    
    /** <p>Identifier of the Fedora object to delete.</p> */
    public static final Property isReferencedBy = m_model.createProperty( "http://example.org/qudex/isReferencedBy" );
    
    /** <p>Identifier of the Fedora object to delete.</p> */
    public static final Property isFormatOf = m_model.createProperty( "http://example.org/qudex/isFormatOf" );
     
    public static Model getModel() {
	ClassLoader classLoader = Thread.currentThread()
	.getContextClassLoader();
	InputStream is;
	is = classLoader.getResourceAsStream("qudex.rdf");

    	Model myModel = ModelFactory.createDefaultModel();
    	
    	try {
    	    myModel.read(is, "");
    	    return myModel;
    	}catch (Exception ex) {
    	    return myModel;
    	}              
    }
    
    public static boolean containsProperty(String localName) {
    	if (StaticQudex.labelCategory.getLocalName().equals(localName) ||
    		StaticQudex.labelCode.getLocalName().equals(localName) ||
    		StaticQudex.labelMemo.getLocalName().equals(localName) ||
    		StaticQudex.category.getLocalName().equals(localName) ||
    		StaticQudex.code.getLocalName().equals(localName) ||
    		StaticQudex.memo.getLocalName().equals(localName) ||
    		StaticQudex.isOriginal.getLocalName().equals(localName) ||
    		StaticQudex.updatePid.getLocalName().equals(localName) ||
    		StaticQudex.deletePid.getLocalName().equals(localName) ||
    		StaticQudex.isLinkedTo.getLocalName().equals(localName) ||
    		StaticQudex.isRelatedTo.getLocalName().equals(localName) ||
    		StaticQudex.isAnnotationOf.getLocalName().equals(localName) ||
    		StaticQudex.isVersionOf.getLocalName().equals(localName) ||
    		StaticQudex.isReferencedBy.getLocalName().equals(localName) ||
    		StaticQudex.isFormatOf.getLocalName().equals(localName))
    	    return true;
    	else return false;
    }
}
